using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using ActiproSoftware.SyntaxEditor.Addons.Simple.Ast;

namespace ActiproSoftware.SyntaxEditor.Addons.Simple.Ast {

	/// <summary>
	/// Represents a variable declaration statement.
	/// </summary>
	public class VariableDeclarationStatement : ActiproSoftware.SyntaxEditor.Addons.Simple.Ast.Statement {

		/// <summary>
		/// Gets the context ID for the variable name.
		/// </summary>
		public const byte VariableNameContextID = ActiproSoftware.SyntaxEditor.Addons.Simple.Ast.Statement.StatementContextIDBase;

		/// <summary>
		/// Gets the minimum context ID that should be used in your code for AST nodes inheriting this class.
		/// </summary>
		/// <remarks>
		/// Base all your context ID constants off of this value.
		/// </remarks>
		protected const byte VariableDeclarationStatementContextIDBase = ActiproSoftware.SyntaxEditor.Addons.Simple.Ast.Statement.StatementContextIDBase + 1;

		/////////////////////////////////////////////////////////////////////////////////////////////////////
		// OBJECT
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Initializes a new instance of the <c>VariableDeclarationStatement</c> class.
		/// </summary>
		/// <param name="variableName">The variable name.</param>
		/// <param name="textRange">The <see cref="TextRange"/> of the AST node.</param>
		public VariableDeclarationStatement(Identifier variableName, TextRange textRange) : this(textRange) {
			// Initialize parameters
			this.VariableName = variableName;
		}

		/// <summary>
		/// Initializes a new instance of the <c>VariableDeclarationStatement</c> class. 
		/// </summary>
		public VariableDeclarationStatement() {}

		/// <summary>
		/// Initializes a new instance of the <c>VariableDeclarationStatement</c> class. 
		/// </summary>
		/// <param name="textRange">The <see cref="TextRange"/> of the AST node.</param>
		public VariableDeclarationStatement(TextRange textRange) : base(textRange) {}

		/////////////////////////////////////////////////////////////////////////////////////////////////////
		// PUBLIC PROCEDURES
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Accepts the specified visitor for visiting this node.
		/// </summary>
		/// <param name="visitor">The visitor to accept.</param>
		/// <remarks>This method is part of the visitor design pattern implementation.</remarks>
		protected override void AcceptCore(AstVisitor visitor) {
			if (visitor.OnVisiting(this)) {
				// Visit children
				if (this.ChildNodeCount > 0)
					this.AcceptChildren(visitor, this.ChildNodes);
			}
			visitor.OnVisited(this);
		}
		
		/// <summary>
		/// Gets the <see cref="SimpleNodeType"/> that identifies the type of node.
		/// </summary>
		/// <value>The <see cref="SimpleNodeType"/> that identifies the type of node.</value>
		public override SimpleNodeType NodeType { 
			get {
				return SimpleNodeType.VariableDeclarationStatement;
			}
		}

		/// <summary>
		/// Gets or sets the variable name.
		/// </summary>
		/// <value>The variable name.</value>
		public Identifier VariableName {
			get {
				return this.GetChildNode(VariableDeclarationStatement.VariableNameContextID) as Identifier;
			}
			set {
				this.ChildNodes.Replace(value, VariableDeclarationStatement.VariableNameContextID);
			}
		}

		/// <summary>
		/// Gets text representing the node that can be used for display, such as in a document outline.
		/// </summary>
		/// <value>Text representing the node that can be used for display, such as in a document outline.</value>
		public override string DisplayText {
			get {
				return "Variable Declaration of " + this.VariableName.Text;
			}
		}

	}

}
